package com.hangan.langchainspringstart.tools;

import cn.hutool.core.util.IdUtil;
import com.hangan.langchainspringstart.model.Volunteer;
import com.hangan.langchainspringstart.service.IVolunteerService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author hang an
 * @since 2025/8/2
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class ReservationTool {
    private final IVolunteerService volunteerService;

    @Tool("预约志愿填报服务")
    public void addReservation(
            @P("考生姓名") String name,
            @P("考生性别") String gender,
            @P("考生手机号") String phone,
            @P("预约沟通时间,格式为 yyyy-MM-dd'T'HH:mm") String communicationTime,
            @P("考生所在省份") String province,
            @P("考生分数") Integer estimatedScore) {
        volunteerService.save(
                Volunteer.builder()
                        .id(IdUtil.getSnowflakeNextId())
                        .name(name)
                        .gender(gender)
                        .phone(phone)
                        .communicationTime(LocalDateTime.parse(communicationTime, DateTimeFormatter.ISO_LOCAL_DATE_TIME))
                        .province(province)
                        .estimatedScore(estimatedScore)
                        .build()
        );
    }

    @Tool("根据考生手机号查询预约单")
    public Volunteer findReservation(@P("考生手机号") String phone) {
        return volunteerService.getByPhone(phone);
    }


}
